package net.viralpatel.contact.dao;
 
import java.util.List;
 
import net.viralpatel.contact.form.Contact;
 
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
@Repository
public class ContactDAOImpl implements ContactDAO {
 
    @Autowired
    private SessionFactory sessionFactory;
 
    public Integer save(Contact contact) {
        
		return (Integer) sessionFactory.getCurrentSession().save(contact);
    }
 
    public List<Contact> findAll() {
 
        return sessionFactory.getCurrentSession().createQuery("from Contact").list();
    }
 
    public Contact findById(Integer id){
    	return (Contact) sessionFactory.getCurrentSession().get(Contact.class,id);
    }

	public void delete(Contact entity) {
		sessionFactory.getCurrentSession().delete(entity);
	}
}